package sky.tro;

import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.util.string.StringValue;
import org.hibernate.Hibernate;


import java.io.Serializable;
import java.lang.reflect.Field;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: Gauss
 * Date: 30.04.13
 * Time: 14:31
 * To change this template use File | Settings | File Templates.
 */
public class TicketFinder implements Serializable {
    private String departureCity;
    private String destinationCity;
    private Date departureFromDate;
    private Date departureToDate;
    private Date destinationFromDate;
    private Date destinationToDate;
    private String ticketType;
    private Integer ticketCount;
    private Integer priceFrom;
    private Integer priceTo;

    public TicketFinder() {
    }

    public String getDepartureCity() {
        return departureCity;
    }

    public void setDepartureCity(String departureCity) {
        this.departureCity = departureCity;
    }

    public String getDestinationCity() {
        return destinationCity;
    }

    public void setDestinationCity(String destinationCity) {
        this.destinationCity = destinationCity;
    }

    public Date getDepartureFromDate() {
        return departureFromDate;
    }

    public void setDepartureFromDate(Date departureFromDate) {
        this.departureFromDate = departureFromDate;
    }

    public Date getDepartureToDate() {
        return departureToDate;
    }

    public void setDepartureToDate(Date departureToDate) {
        this.departureToDate = departureToDate;
    }

    public Date getDestinationFromDate() {
        return destinationFromDate;
    }

    public void setDestinationFromDate(Date destinationFromDate) {
        this.destinationFromDate = destinationFromDate;
    }

    public Date getDestinationToDate() {
        return destinationToDate;
    }

    public void setDestinationToDate(Date destinationToDate) {
        this.destinationToDate = destinationToDate;
    }

    public String getTicketType() {
        return ticketType;
    }

    public void setTicketType(String ticketType) {
        this.ticketType = ticketType;
    }

    public Integer getTicketCount() {
        return ticketCount;
    }

    public void setTicketCount(Integer ticketCount) {
        this.ticketCount = ticketCount;
    }

    public Integer getPriceFrom() {
        return priceFrom;
    }

    public void setPriceFrom(Integer priceFrom) {
        this.priceFrom = priceFrom;
    }

    public Integer getPriceTo() {
        return priceTo;
    }

    public void setPriceTo(Integer priceTo) {
        this.priceTo = priceTo;
    }

    public List<ParameterAndCriteria> getCriteriaList() {
        List<ParameterAndCriteria> list = new ArrayList<ParameterAndCriteria>();
        if (departureCity != null) {
            //0 - equals
            //1 - less or equals
            //2 - more or equals
            list.add(new ParameterAndCriteria("departureAirport.city.name",
                    0, departureCity, Hibernate.STRING));
        }
        if (destinationCity != null) {
            list.add(new ParameterAndCriteria("destinationAirport.city.name",
                    0, destinationCity, Hibernate.STRING));
        }
        if (departureFromDate != null) {
            list.add(new ParameterAndCriteria("departureDate",
                    2, departureFromDate, Hibernate.TIMESTAMP));
        }
        if (departureToDate != null) {
            list.add(new ParameterAndCriteria("departureDate",
                    1, departureToDate, Hibernate.TIMESTAMP));
        }
        if (destinationFromDate != null) {
            list.add(new ParameterAndCriteria("destinationDate",
                    2, destinationFromDate, Hibernate.TIMESTAMP));
        }
        if (destinationToDate != null) {
            list.add(new ParameterAndCriteria("destinationDate",
                    1, destinationToDate, Hibernate.TIMESTAMP));
        }
        list.add(new ParameterAndCriteria("free"+ticketType+"Places",
                2, ticketCount, Hibernate.INTEGER));
        if (priceFrom != null) {
            list.add(new ParameterAndCriteria(ticketType.replaceFirst("[A-Z]{1}", ticketType.substring(0,1).toLowerCase())+"Cost",
                    2, priceFrom, Hibernate.INTEGER));
        }
        if (priceTo != null) {
            list.add(new ParameterAndCriteria(ticketType.replaceFirst("[A-Z]{1}", ticketType.substring(0,1).toLowerCase())+"Cost",
                    1, priceTo, Hibernate.INTEGER));
        }
        return list;
    }
}
